package com.hongxin.nw.netty.down;

import com.hongxin.nw.netty.model.Transfer;
import com.hongxin.nw.netty.model.packing.ASDUccina1;
import com.hongxin.nw.netty.utils.FieldPack;
import com.hongxin.nw.netty.utils.pools.AsduStartPools;
import com.hongxin.nw.netty.values.StaticValue;
import com.hongxin.nw.netty.values.TypeIdentif;

/**
 * @remark 计数量总召
 * @author: GuoXiaolin
 * @date 2019/6/25 15:57
 * @Version 1.0
 * @Descibe
 */
public class CSummonReq implements  IChannelRequest {
    @Override
    public String doPacking(Transfer transfer)  throws Exception{
        String code = transfer.getCode();
        //TYPE = 101 , COT = 6
        ASDUccina1 mm = new ASDUccina1();
        mm.setQcc(TypeIdentif.QCC_RQT_ONE.getInt(),  TypeIdentif.QCC_FRZ_THREE.getInt());

//        as.setType(TypeIdentif.IDENTIFY_C_CI_NA_1.getInt());
//        as.setCot( TypeIdentif.COT_ACTIVATION.getInt());
//        as.setStaadr(AsduStartPools.getAsduStart(code).getStatAddress());
//        as.setInfoadr(0);
//        as.setVsq(StaticValue.DEFAULT_VSQ, StaticValue.SQ0);

        String as = FieldPack.packASDU(TypeIdentif.IDENTIFY_C_CI_NA_1.getInt(),
                TypeIdentif.COT_ACTIVATION.getInt(),
                AsduStartPools.getAsduStart(code).getStatAddress(),0,
                StaticValue.DEFAULT_VSQ, StaticValue.SQ0);

        String data = as + mm.getHexData();

//        APCI ac = new APCI();
//        ac.setIdentifyStart(TypeIdentif.IDENTIFY_START.getInt());
//        ac.setApduLength(as.getHexData().length()/2);
//        ac.setContarea(TypeIdentif.FORMAT_I.getStr(), StaticValue.U_TEST_V);
//        return ac.getHexData() + as.getHexData();

        String ac = FieldPack.packAPCI(data.length(), TypeIdentif.FORMAT_I.getStr(), StaticValue.U_TEST_V);
        return ac + data;
    }
}
